package com.wkg.lotterysystem.dao.mapper;

import com.wkg.lotterysystem.dao.dataobject.ActivityDo;
import com.wkg.lotterysystem.dao.dataobject.ActivityUserDo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {

    @Insert({
            " <script>",
            " INSERT INTO activity_user (activity_id, user_id, user_name, status) VALUES",
            " <foreach collection='items' item='item' index='index' separator=','>",
            " (#{item.activityId}, #{item.userId}, #{item.userName}, #{item.status})",
            " </foreach>",
            " </script>"
    })
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    int batchInsert(@Param("items") List<ActivityUserDo> activityUserDoList);

    @Select("select * from activity_user where activity_id = #{activityId}")
    List<ActivityUserDo> selectByActivityId(@Param("activityId") Integer activityId);

    @Select({
            " <script>",
            " select * from activity_user " +
                    " where activity_id =#{activityId} " +
                    " and user_id in",
            " <foreach collection='userIds' item='userId' open ='(' separator=', ' close=')'  >",
            " #{userId}",
            " </foreach>",
            " </script>"})
    List<ActivityUserDo> batchSelectByAUIds(@Param("activityId") Integer activityId,
                                            @Param("userIds") List<Integer> userIds);


    @Update({
            " <script>",
            " update activity_user set status =#{status}" +
                    " where activity_id =#{activityId} " +
                    " and user_id in",
            " <foreach collection='userIds' item='userId' open ='(' separator=', ' close=')'  >",
            " #{userId}",
            " </foreach>",
            " </script>"})
    void batchUpdateStatus(@Param("activityId") Integer activityId,
                           @Param("userIds") List<Integer> userIds,
                           @Param("status") String status);
}



